<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<script type="text/javascript" src="../js/jquery-1.8.0.min.js" ></script>
		<script type="text/javascript" src="../js/head_public.js" ></script>
		<script type="text/javascript" src="../js/session.js" ></script>
		<script type="text/javascript" src="../js/common.js" ></script>
		<style>
			.baocun{color: #fff;border: 1px solid #fff;background: #ff7e00;position: absolute;z-index: 10;top: 0.12rem;right: 0.2rem;}
		</style>
	</head>

	<body style="background: #fff;">
		<header class="mui-bar mui-bar-nav ding-bar">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title" style="position: relative;width: 80%;">重设登录密码 <button class="baocun">保存</button></h1>
		   
		</header>
		<div class="mui-content" style="background: #fff;">
		    <form class="changep-form" id="form">
		    	<p><span>原密码：</span><input type="password" name="old_password" placeholder="请输入原密码"></p>
		    	<p><span>新密码：</span><input type="password" name="password" placeholder="请输入新密码"></p>
		    	<p><span>确认密码：</span><input type="password" name="confirm_password" placeholder="请输入确认密码"></p>
		        <!--<p style="color: #ff7e00;border: none;" id="wang-btn">忘记密码？</p>-->
		    </form>
		    <div class="forget-container" >
		    	
		    	<div class="cg-pass-menban"></div>
		    	<div class="forget-con">
		    		<div style="position: relative;">
		    			<img src="../images/close.png" class="wang-close"/>
			    		<h1 style="font-weight: normal;font-size: 0.4rem;text-align: center;">忘记密码</h1>
			    		<h2 class="wang-phone" id="shoujihao">已绑定手机号：189****9999</h2>
			    		<form class="changep-form" id="wang-from">
			    			<input type="hidden" id="true_yanzheng"/>
					    	<p class="wang-yanzheng"><input type="text" name="sms_captcha"  placeholder="请输入验证码"><button type="button" id="hqyzm">发送验证码</button></p>
					    	<p><span>新密码：</span><input type="password" name="member_password" placeholder="请输入新密码"></p>
					    	<p><span>确认密码：</span><input type="password" name="report_password"  placeholder="请输入确认密码"></p>
					        <button class="wang-qr" id="wjma">确认</button>
			    		</form>
		    		</div>
		    		

		    	</div>
		    </div>
		</div>
		
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript">
			mui.init()
			var phone="";
			var userid=getCookie("userid");
			if(userid==""||userid==null){
				alert("您还没有登录，请登录！")
				location.href="../public/login.html"
			}
		
			mui(".mui-content").on("tap","#wang-btn",function(){
					//获取个人信息
				var  data={};	    
	        	data.member_id=userid;
	        	var phonestr="";
	            $.post(net+"public/index.php?s=api/member",data,function(res){
	            	if(res.code=="200"){	
	            		phone=res.result.member_mobile;
	            		phonestr=phone.substring(0,3)+"****"+phone.substring(7,phone.length)
	            		$("#shoujihao").html("已绑定手机号："+phonestr)
	            	}
	            })
				$(".forget-container").show();
				var t =59;
				// 验证码获取倒计时
				mui(".forget-container").on("tap","#hqyzm",function(){
					  // 检查手机号格式
					  disableBtn(this);
					  var username =/^1[0-9]{10,10}$/;
				      
					  if(phone==null||phone==''){
					    alert("账号不能为空");
					    return false;
					  }else if(!username.test(phone)){
					    alert("手机号格式不正确");
					    return false;
					  }
					  
					   $(this).css("background-color","#999");
					  var param = {};  //register
					  // Checkphone			
					  param.sms_mobile = phone;
					  param.type = "3";
			          param.member_id=userid;
					  // 判断返回值
					  console.log(param)
					  $.post(net+"/public/index.php?s=api/login/get_captcha",param,function(res){
					  	  if (res.code=="200") {
							$("#hqyzm").attr("disabled","disabled");
							$("#hqyzm").css({"background-color":"#999","border-color":"#999"});
						  	var inter=setInterval("refer()",1000); //启动1秒定时
						    $("#true_yanzheng").val(res.result.sms_captcha);
						  }else {
						    alert(data.msg);
						  }
					  }) 
				})
				mui(".forget-container").on("tap","#wjma",function(){
					var $passwd = /^\w{6,12}$/;
					var params = $("#wang-from").serializeObject();
					//验证表单
					if(params.sms_captcha==""||params.sms_captcha==null){
		            	alert("请填写手机验证码")
		            	return false;
					}else if(params.member_password==""||params.member_password==null){
						alert("请填写新密码")
						return false;
					}else if(!$passwd.test(params.member_password)){
						alert("新密码为6-12字母或者数字！")
						return false;
					}else if(params.report_password==""||params.report_password==null){
						alert("请填写确认密码");
						return false;
					}else if(!$passwd.test(params.report_password)){
						alert("确认密码为6-12字母或者数字！")
						return false;
					}else if(params.report_password!=params.member_password){
						alert("新密码与确认密码不一致")
						return false;
					}
					params.member_id=userid;
					params.sms_mobile=phone;
					params.true_captcha=$("#true_yanzheng").val();
					$.post(net+"/public/index.php?s=api/login/forgetpass",params,function(res){
						alert(res.message)
					})
				})
			})
					//倒计时
		    var t=59;
			function refer()
			{
			  if(t==0)
			  {
			    $("#hqyzm").prop("disabled",false);//取消禁用
			    $("#hqyzm").css({"background-color":"#ff7e00","border-color":"#ff7e00"});
			    $("#hqyzm").html("获取验证码");
			  }else{
			    $("#hqyzm").html("获取验证码"+t+"s");
			    t--; // 计数器递减
			  }
			}
			mui(".forget-container").on("tap",".wang-close",function(){
				$(".forget-container").hide();
			})
			$(function(){
				var userid=getCookie("userid");
				if(userid==""||userid==null){
					 	location.href="login.html";
				}else{
				
					mui("header").on("tap",".baocun",function(){
						var $passwd = /^\w{6,12}$/;
			            var params = $("#form").serializeObject();//将表单序列化为JSON对象
			            if(params.old_password==""||params.old_password==null){
			            	alert("请填写原密码")
			            	return false;
						}else if(!$passwd.test(params.old_password)){
							alert("密码为6-12字母或者数字！")
							return false;
						}else if(params.password==""||params.password==null){
							alert("新密码不能为空！");
							return false;
						}else if(!$passwd.test(params.password)){
							alert("新密码为6-12字母或者数字！")
							return false;
						}else if(params.confirm_password==""||params.confirm_password==null){
							alert("确认密码不能为空！")
							return false;
						}else if(!$passwd.test(params.confirm_password)){
							alert("确认密码为6-12字母或者数字！")
							return false;
						}else if(params.confirm_password!=params.password){
							alert("新密码与确认密码不一致")
							return false;
						}
						
						params.member_id=userid;
						$.post(net+"/public/index.php?s=api/member/modify_pwd",params,function(res){
							if(res.code=="10001"){
								alert(res.message)
							}else if(res.code=="200"){
								alert(res.message)
								mui.back();
							}
							
						})
					})
				}
			})
			//序列化
			 $.fn.serializeObject = function() {  
		        var o = {};  
		        var a = this.serializeArray();  
		        $.each(a, function() {  
		            if (o[this.name]) {  
		                if (!o[this.name].push) {  
		                    o[this.name] = [ o[this.name] ];  
		                }  
		                o[this.name].push(this.value || '');  
		            } else {  
		                o[this.name] = this.value || '';  
		            }  
		        });  
		        return o;  
		    }
		
		</script>
	</body>

</html>